<template>
	<view class="main">
		<tou_hand1 handtitle='预警设置'></tou_hand1>
		<view class="show">
			<view class="sone">
				<span>姓名</span>
				<span>是否开启预警</span>
			</view>
			<view class="stwo" v-for="(item, index) in showlist" :key="index">
				<view class="stwotxt">{{item.name}}</view>
				<van-switch :checked="item.type" @change="onInput(item)"/>
			</view>
		</view>
		
	</view>
</template>

<script>
	import tou_hand1 from '../../components/tou_hand1/tou_hand1.vue'
	
	export default {
		components: {tou_hand1},
		mounted() {
			
		},

		data() {
			return {
				showlist:[],
				projectId:'',
				userIds:''
			}
		},
		onLoad(options) {
			this.projectId=options.projectId
		},
		onShow() {
			this.show()
		},
		methods: {
			show(){
				this.$base.request1('manager/project/warning'+'/'+this.projectId, 'GET')
					.then(res => {
						var arr=res.data.data
						for(var i=0;i<arr.length;i++){
							if(arr[i].isSet==0){
								arr[i].type=false
							}else{
								arr[i].type=true
							}
						}
						this.showlist=arr
					})
					.catch(err => {
				
					})
			},
			//修改预计信息
			onInput(item){
				console.log(item);
				var arr=this.showlist
				console.log(arr);
				this.userIds=''
				for(var i=0;i<arr.length;i++){
					if(arr[i].userId == item.userId){
						arr[i].type = !arr[i].type
					}
					if(arr[i].type==true){
						if(!this.userIds){
							this.userIds=arr[i].userId
						}else{
							this.userIds=this.userIds+','+arr[i].userId
						}
					}
				}
				let data={
					projectId:this.projectId,
					userIds:this.userIds
				}
				this.$base.request1('manager/project/warning', 'PUT',data)
					.then(res => {
						if(res.data.code==200){
							uni.showToast({
								title: '修改成功',
								duration: 2000,
							});
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					})
					.catch(err => {
				
					})
			}
			
			
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		overflow-x: hidden;
	
		.show{
			width: 100%;
			box-sizing: border-box;
			padding: 0 32upx;
			.sone{
				display: flex;
				justify-content: space-between;
				width: 100%;
				box-sizing: border-box;
				padding: 62upx 80upx 24upx 99upx;
				font-size: 32upx;
				font-family: PingFang SC Bold, PingFang SC Bold-Bold;
				font-weight: 700;
				color: #333333;
				border-bottom: 1upx solid #d5d5d5;
			}
			.stwo{
				width: 100%;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				padding: 0upx 136upx 0upx 90upx;
				margin-top: 36upx;
				.stwotxt{
					font-size: 28upx;
					font-family: PingFang SC Bold, PingFang SC Bold-Bold;
					font-weight: 700;
					color: #333333;
				}
			}
		}
		
	}
</style>
